package com.luyou.servlet;

import java.io.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

/**
 *  WebServlet(name  = "helloServlet", value = "/hello_servlet")
 *  同下
 *  <servlet>
 *      <servlet-name>helloServlet</servlet-name>
 *      <servlet-class>com.luyou.servlet.HelloServlet</servlet-class>
 *  </servlet>
 *  <servlet-mapping>
 *      <servlet-name>helloServlet</servlet-name>
 *      <url-pattern>/hello_servlet</url-pattern>
 *  </servlet-mapping>
 */
//@WebServlet(name = "helloServlet", value = "/hello_servlet")
public class HelloServlet extends HttpServlet {
    private String message;

    public void init() {
        System.out.print("我被初始化了");
        message = "Hello World!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");

        // Hello
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<h1>" + message + "</h1>");
        out.println("</body></html>");
    }

    public void destroy() {
        System.out.print("我被销毁了");
    }

}